package com.tianhui.consignortwofei.pattern.orderOprate.impl;

import android.content.Context;

import androidx.annotation.NonNull;

import com.fgs.common.CommonModel;
import com.fgs.common.CommonResponse;
import com.fgs.common.api.CommonConfig;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.fgs.common.utils.ToastUtil;
import com.fgs.common.widget.dialog.OperateTipDialog;
import com.tianhui.consignortwofei.api.OrderApiService;
import com.tianhui.consignortwofei.manager.EventBusManage;
import com.tianhui.consignortwofei.mvp.model.enty.OrderOperateInfo;
import com.tianhui.consignortwofei.pattern.orderOprate.IOrderOperate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fgs
 * @date 2020/9/21
 * @description 撤销计算
 **/
public class RevokeFreightOperate implements IOrderOperate {
    @Override
    public void orderOperate(Context context, OrderOperateInfo operateInfo) {


        new OperateTipDialog.Builder(context)
                .title("提示")
                .content("是否撤销计算？")
                .positiveText("确定")
                .onPositive(new OperateTipDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull OperateTipDialog dialog) {
                        dialog.dismiss();
                        Map<String, String> map = new HashMap<>();
                        map.put("id", operateInfo.orderInfo.fcid);

                        new CommonModel().subscribe(context, CommonConfig.getInstance().create(OrderApiService.class).revokeFreightCalculation(map), new ObserverResponseListener<CommonResponse>() {
                            @Override
                            public void onNext(CommonResponse commonResponse) {
                                if (commonResponse.getCode() == 20000) {
                                    EventBusManage.refreshOrderDetail();
                                    EventBusManage.refreshOrderList();
                                } else {
                                    ToastUtil.showShortToast(commonResponse.getMsg());
                                }

                            }

                            @Override
                            public void onError(ExceptionHandle.ResponseThrowable e) {
                                ToastUtil.showShortToast(e.message);
                            }
                        });
                    }
                })
                .negativeText("取消")
                .show();


    }
}
